package com.xh.petdogexpert.base;


import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import com.fasterxml.jackson.databind.ObjectMapper;

public class BaseController {
	
	@ResponseBody
	@ExceptionHandler(value = BaseException.class)
	private Object handleBaseException(BaseException baseException) {

		if(baseException.errorType == BaseException.HTML_ERROR) {
			return "<script>alert('" + baseException.getErrorMsg() + "');</script>";
		}

		ResponseData rData = new ResponseData();
		rData.wrapBaseException(baseException);
		return rData;
	}
	
	@ResponseBody
	@ExceptionHandler(value = Exception.class)
	private ResponseData handleException(Exception exception) {
		exception.printStackTrace();
		ResponseData rData = new ResponseData();
		rData.setSuccess(false);
		rData.setErrorType(BaseException.UNKNOW);
		return rData;
	}
}
